% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/statestats_query.R
\name{usastats_query}
\alias{usastats_query}
\title{usastats_query - convenient way to see US mean, pctiles of Envt and Demog indicators in lookup table}
\usage{
usastats_query(
  varnames = c(EJAM::names_e, EJAM::names_d, EJAM::names_d_subgroups_nh),
  PCTILES = NULL,
  dig = 4
)
}
\arguments{
\item{varnames}{names of columns in lookup table, like "proximity.rmp"}

\item{PCTILES}{vector of percentiles 0-100 and/or "mean"}

\item{dig}{how many digits to round to}
}
\description{
usastats_query - convenient way to see US mean, pctiles of Envt and Demog indicators in lookup table
}
\details{
A long list of variables: usastats_query(intersect(EJAM::names_all_r,  names(EJAM::usastats)))
}
\examples{
\dontrun{

usastats_querye() 
#  data.frame where names_e are the names(), 
#  means plus other percentiles, and there are other cols REGION PCTILE

avg.in.us                # This is a data.frame, 1 row, where colnames are indicators
avg.in.us[names_e]          # subset is a data.frame!
unlist(avg.in.us[names_e])  # to make it a vector

usastats_means()        # This is a matrix, with 1 col, and indicator names are rownames
usastats_means(names_e)     # subset is a matrix        and indicator names are rownames
usastats_means()[names_e, ] # subset is a named vector  and indicator names are  names

usastats_means()
statestats_query()

statestats_query()[,names_d]
statestats_query(varnames = names_d)

statestats_query()[,names_e]
statestats_query(varnames = names_e)

statestats_query(varnames = names_d_subgroups)
head(statestats_query(varnames = longlist))

## in USA overall, see mean and key percentiles
# for all demog and envt indicators
usastats_query() # or statestats_query('us') 
# can say us or US or USA or usa etc.
usastats_query(PCTILES = 'mean')
usastats_means() # same but nicer looking format in console
usastats_means(dig=4)

# long list of variables:
x = intersect(EJAM::names_all_r,  names(EJAM::usastats))
usastats_means(x)

usastats[!(usastats$PCTILE < 50), c("PCTILE", names_d)]
usastats[!(usastats$PCTILE < 50), c("PCTILE", names_e)]

## in 1 state, see mean and key percentiles for all demog and envt indicators
statestats_query('MD')

## in 1 state, see mean and key percentiles for just demog indicators
statestats_queryd('MD')

## 1 indicator in 1 state, see a few key percentiles and mean
statestats_query('MD','proximity.tsdf')

## mean of 1 indicator for each state
statestats_query(varnames = 'proximity.tsdf')

## using full blockgroup dataset, not lookup tables of percentiles, 
blockgroupstats[, lapply(.SD, function(x) mean(x, na.rm=T)),
   .SDcols= c(names_d, names_e)]

##   see all total counts (not just US means), 
##   demographics including subgroups, 
##   but not environmental indicators.
t(blockgroupstats[, lapply(.SD, function(x) mean(x, na.rm=T)),
    .SDcols= c(names_e, names_d)])

}

}
